package com.hopu.blb_erp.controller;



import com.hopu.blb_erp.entity.Laser;
import com.hopu.blb_erp.entity.PageEntity;
import com.hopu.blb_erp.entity.PageEntityP;
import com.hopu.blb_erp.service.ILaserService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import org.springframework.stereotype.Controller;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author A-Zhang
 * @since 2021-11-23
 */
@RestController
public class LaserController {
    @Autowired
    private ILaserService LaserService;

    @ApiOperation("分页查询激光码")
    @GetMapping("/Laser/page")
    public ResponseEntity<PageEntityP> findPage(@RequestParam(value = "current", required = false,defaultValue = "1")
                                                       Integer current){
        PageEntityP<Laser> page = LaserService.findPage(current);
        return ResponseEntity.ok(page);
    }
    @ApiOperation("根据状态码已生产还是未生产")
    @GetMapping("/Laser2/page/{status}")
    public ResponseEntity<List<Laser>> findPage2(@PathVariable Integer status){
        System.out.println("我进来了");
        ArrayList<Laser> Lasers = LaserService.selecLasersByStatus2(status);
        for (Laser Laser : Lasers) {
            System.out.println(Laser+"======>>>");
        }
        return ResponseEntity.ok(Lasers);
    }

    @PutMapping("/Lasers/{ids}")
    public ResponseEntity<String> modifyLasers(@PathVariable("ids") List<Integer> ids){
        LaserService.modifyLasers(ids);
        return ResponseEntity.ok("ok");
    }

    @PutMapping("/Lasers2/{ids}")
    public ResponseEntity<String> modifyLasers2(@PathVariable("ids") List<Integer> ids){
        LaserService.modifyLasers2(ids);
        return ResponseEntity.ok("ok");
    }
    @ApiOperation("根据lNo查询激光码")
    @GetMapping("/Laser")
    public ResponseEntity<List<Laser>> findLaserBylNo(@RequestParam("input")String input ){
        Laser LaserBylNo = LaserService.findLaserBylNo(input);

        List<Laser> Lasers = new ArrayList<>();
        Lasers.add(LaserBylNo);
        return ResponseEntity.ok(Lasers);
    }

    @ApiOperation("批量删除所有激光码")
    @DeleteMapping("/Lasers/{ids}")
    public ResponseEntity<String> removeLasers(@PathVariable("ids")List<Integer> ids){
        LaserService.removeLasers(ids);
        return ResponseEntity.ok("ok");
    }
}
